package com.nowcoder.Offer.Stack;


import org.junit.Test;

import java.util.Stack;

/**
 * 判断是否是栈的弹出序列
 */
public class VertifyStackSeq {
    public boolean IsPopOrder(int [] pushA,int [] popA) {
        Stack<Integer> stack = new Stack<>();
        for(int popIndex = 0, pushIndex = 0; pushIndex<pushA.length; pushIndex++){
            stack.push(pushA[pushIndex]);
            while(!stack.isEmpty() && stack.peek() == popA[popIndex]){
                stack.pop();
                popIndex++;
            }
        }
        return stack.isEmpty();
    }

    @Test
    public void test(){
        int[] push = {1,2,3,4,5};
        int[] pop = {4,3,5,1,2};
        System.out.println(IsPopOrder(push,pop));
    }
}
